package whf.survey.entity;

import java.text.DecimalFormat;

import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;

import whf.framework.entity.AbstractEntity;


/**
 * @author wanghaifeng
 * @create Sep 12, 2006 10:17:14 PM
 * 
 */
public class AnswerResult extends AbstractEntity {
	private SurveyTopicChoice choice;
	
	private int count;
	
	private String answer;
	
	private String type;
	
	private int totalCount;
	
	public AnswerResult(String type, SurveyTopicChoice choice, int count){
		this.type = type;
		this.choice = choice;
		this.count = count;
	}
	
	public AnswerResult(String type, String answer){
		this.type = type;
		this.answer = answer;
	}

	/**
	 * @return Returns the answers.
	 */
	public String getAnswer() {
		return answer;
	}

	/**
	 * @return Returns the choice.
	 */
	public SurveyTopicChoice getChoice() {
		return choice;
	}

	/**
	 * @return Returns the count.
	 */
	public int getCount() {
		return count;
	}

	/**
	 * @return Returns the type.
	 */
	public String getType() {
		return type;
	}

	/**
	 * @return Returns the totalCount.
	 */
	public int getTotalCount() {
		return totalCount;
	}

	/**
	 * @param totalCount The totalCount to set.
	 */
	public void setTotalCount(int totalCount) {
		this.totalCount = totalCount;
	}
	
	public double getPercentage(){
		if(this.totalCount == 0) return 0;
		return this.count * 100.0 / (this.totalCount * 1.0);
	}
	
	public String getPercentage2(){
		DecimalFormat df = new java.text.DecimalFormat("0");
		return df.format(this.getPercentage());
	}
	
	public String toString(){
		return ToStringBuilder.reflectionToString(this, ToStringStyle.MULTI_LINE_STYLE);
	}
}